package com.edu.kindergarten.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.edu.kindergarten.entity.NotiAndSuggestionEntity;
import com.edu.kindergarten.utils.LogUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class NotiAndSuggestionListAdapter extends BaseAdapter {

	private static final String TAG = "NotiAndSuggestionListAdapter";

	private Context context;
	private int layoutId;
	private List<NotiAndSuggestionEntity> listData;
	private int to[];

	public NotiAndSuggestionListAdapter(Context context, int layoutId,
			List<NotiAndSuggestionEntity> listData, int to[]) {
		this.context = context;
		this.layoutId = layoutId;
		this.listData = listData;
		this.to = to;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		LogUtils.d(TAG, "constructor,listData size:" + listData.size());
		return listData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LogUtils.d(TAG, "getView, position=" + position);
		
		ViewHolder holder;
		
		if (convertView == null) {
			LayoutInflater layoutInflator = LayoutInflater.from(context);
			convertView = layoutInflator.inflate(layoutId, parent, false);
			holder = new ViewHolder();
			holder.listItem = (LinearLayout) convertView.findViewById(to[0]);
			holder.indicatorIcon = (ImageView) convertView.findViewById(to[1]);
			holder.postDay = (TextView) convertView.findViewById(to[2]);
			holder.postYM = (TextView) convertView.findViewById(to[3]);
			holder.msgTitle = (TextView) convertView.findViewById(to[4]);
			holder.msgSummary = (TextView) convertView.findViewById(to[5]);

//			holder.listItem.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View arg0) {
//					// TODO Auto-generated method stub
//					UiUtils.showShortToast(context,
//							R.string.function_not_implement);
//				}
//			});

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.postDay.setText(listData.get(position).getTimeDay());
		holder.postYM.setText(listData.get(position).getTimeYM());
		holder.msgTitle.setText(listData.get(position).getTitle());
		holder.msgSummary.setText(listData.get(position).getSummary());
		
		ImageLoader.getInstance().displayImage(listData.get(position).getImageList().get(0), holder.indicatorIcon);
		
		return convertView;
	}

	static class ViewHolder {
		LinearLayout listItem;
		ImageView indicatorIcon;
		TextView postDay;
		TextView postYM;
		TextView msgTitle;
		TextView msgSummary;
	}

}
